home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / show3.pro < prev    next >
Text File  |  1997-07-08  |  6KB  |  163 lines

  1. ; $Id: show3.pro,v 1.6 1997/03/10 23:58:49 griz Exp $
  2. ;
  3. ; Copyright (c) 1988-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. PRO show3, image, x, y, INTERP = interp, SSCALE=sscale, E_CONTOUR=ec, $
  7.     E_SURFACE=es
  8. ; Show an image three ways...
  9. ;+
  10. ; NAME:
  11. ;    SHOW3
  12. ;
  13. ; PURPOSE:
  14. ;    Show a 2D array three ways in a display that combines SURFACE, 
  15. ;    CONTOUR, and an image (color/gray scale pixels).
  16. ;
  17. ; CATEGORY:
  18. ;    Display, graphics.
  19. ;
  20. ; CALLING SEQUENCE:
  21. ;    SHOW3, Image [, INTERP = Interp, SSCALE = Sscale]
  22. ;
  23. ; INPUTS:
  24. ;    Image:    The 2-dimensional array to display.
  25. ;
  26. ; OPTIONAL INPUTS:
  27. ;    X = a vector containing the X values of each column of Image.
  28. ;        If omitted, columns have X values 0, 1, ..., Ncolumns-1.
  29. ;    Y = a vector containing the Y values of each row of Image.
  30. ;        If omitted, columns have Y values 0, 1, ..., Nrows-1.
  31. ; KEYWORD PARAMETERS:
  32. ;    INTERP:    Set this keyword to use bilinear interpolation on the pixel 
  33. ;        display.  This technique is slightly slower, but for small 
  34. ;        images, it makes a better display.
  35. ;
  36. ;    SSCALE:    Reduction scale for surface. The default is 1.  If this
  37. ;        keyword is set to a value other than 1, the array size 
  38. ;        is reduced by this factor for the surface display.  That is, 
  39. ;        the number of points used to draw the wire-mesh surface is
  40. ;        reduced.  If the array dimensions are not an integral multiple
  41. ;        of SSCALE, the image is reduced to the next smaller multiple.
  42. ;    E_CONTOUR: a structure containing additional keyword parameters
  43. ;        that are passed to the CONTOUR procedure.  See the example
  44. ;        below.
  45. ;    E_SURFACE: a structure containing additional keyword parameters
  46. ;        that are passed to the SURFACE procedure.  See the example
  47. ;        below.
  48. ;
  49. ; OUTPUTS:
  50. ;    No explicit outputs.
  51. ;
  52. ; COMMON BLOCKS:
  53. ;    None.
  54. ;
  55. ; SIDE EFFECTS:
  56. ;    A new plot is generated.
  57. ;
  58. ; RESTRICTIONS:
  59. ;    The display gets too "busy" when displaying larger (say 50 by 50),
  60. ;    images, especially if they are noisy.  It can be helpful to use
  61. ;    the SSCALE keyword or the SMOOTH and/or REBIN functions to smooth the 
  62. ;    surface plot.
  63. ;
  64. ;    You might want to modify the calls to CONTOUR and SURFACE slightly
  65. ;    to customize the display to your tastes, i.e., with different colors,
  66. ;    skirts, linestyles, contour levels, etc.
  67. ;
  68. ; PROCEDURE:
  69. ;    First, do a SURFACE with no data to establish the 3D to 2D scaling.
  70. ;    Then convert the coordinates of the corner pixels of the array to
  71. ;    2D.  Use POLYWARP to get the warping polynomial to warp the
  72. ;    2D image into the area underneath the SURFACE plot.  Output the image,
  73. ;    output the surface (with data) and then output the contour plot at
  74. ;    the top (z=1).
  75. ;
  76. ; EXAMPLES:
  77. ;    A = BESELJ(SHIFT(DIST(30,20), 15, 10)/2.,0)  ;Array for example
  78. ;    SHOW3, A        ;Show it with default display.
  79. ;    SHOW3, A, SQRT(FINDGEN(30))  ;Make X axis proportional to sqrt
  80. ;    SHOW3, A, E_CONTOUR={C_CHARSIZE:2, DONW:1} ;Label CONTOUR lines with
  81. ;        double size characters, and include downhill tick marks.
  82. ;    SHOW3, A, E_SURFACE={SKIRT:-1, ZRANGE:[-2,2]}  ;Draw a surface with
  83. ;        a skirt and scale Z axis from -2 to 2.
  84. ; MODIFICATION HISTORY:
  85. ;    DMS. Jan, 1988.
  86. ;    Added fudges for PostScript, April, 1988.
  87. ;    Fixed bug where contour plot was occasionally clipped. Dec, 1990.
  88. ;    Added optional axis variables, and _EXTRA keywords for CONTOUR,
  89. ;        and SURFACE.  Jan, 1996.
  90. ;    DD.  Added code to ignore !ORDER for the TV of the image.  Mar 1997.
  91. ;-
  92. on_error,2              ;Return to caller if an error occurs
  93. s = size(image)        ;Get size of image
  94. nx = s[1]        ;Columns
  95. ny = s[2]        ;Rows
  96.  
  97. if n_elements(sscale) eq 0 then sscale = 1 ;Default scale
  98. sscale = fix(sscale)        ;To Integer
  99.  
  100. if n_elements(x) eq 0 then x = findgen(nx)    ;Axis vectors
  101. if n_elements(y) eq 0 then y = findgen(ny)
  102.  
  103. if ((nx mod sscale) ne 0) or ((ny mod sscale) ne 0) then begin
  104.     nx = (nx/sscale) * sscale ;To multiple
  105.     ny = (ny/sscale) * sscale
  106.     img = image[0:nx-1, 0:ny-1]
  107.     xx = x[0:nx-1]
  108.     yy = y[0:ny-1]
  109. endif else begin
  110.     img = image
  111.     xx = x
  112.     yy = y
  113. endelse
  114.  
  115.         ;Set up scaling
  116. SURFACE, img, xx, yy, /SAVE,/NODATA,XST=1,YST=1,ZAXIS=1, _EXTRA=es
  117. empty            ;Don't make 'em wait watching an empty screen.
  118.  
  119. xorig = [x[0],x[nx-1],x[0],x[nx-1]]    ;4 corners X locns in image
  120. yorig = [y[0],y[0],y[ny-1],y[ny-1]]    ;4 corners Y locns
  121.  
  122. xc = xorig * !x.s[1] + !x.s[0]    ;Normalized X coord
  123. yc = yorig * !y.s[1] + !y.s[0]    ;Normalized Y
  124.             ;To Homogeneous coords,  and transform
  125. p = [[xc],[yc],[fltarr(4)],[replicate(1,4)]] # !P.T 
  126. u = p[*,0]/p[*,3] * !d.x_vsize    ;Scale U coordinates to device
  127. v = p[*,1]/p[*,3] * !d.y_vsize    ;and V
  128. ;
  129. ;    Now, the 4 corners of the place for the image are in u and v
  130. ;
  131. u0 = min(u) & v0 = min(v)        ;Lower left corner of screen box
  132. su = max(u)- u0+1 & sv = max(v) - v0+1    ;Size of new image
  133. if (!d.flags and 1) eq 1 then begin    ;Scalable pixels (PostScript)?
  134.     fact = 50        ;Yes, shrink it
  135.     miss = 255        ;Missing values are white
  136.     c_color=[0,0]        ;Contour in only one color, black
  137.  endif else begin
  138.     fact = 1         ;one pixel/output coordinate
  139.     miss = 0        ;missing is black
  140.     c_color=[150,200,250]
  141.  endelse
  142.  
  143. if (!d.flags and 512) ne 0 then $  ;White background?
  144.     miss = 255 else miss = 0
  145. ;
  146.     ;Get polynomial coeff for warp
  147. if !d.n_colors gt 2 then top = !d.n_colors -1 else top = 255
  148.  
  149. POLYWARP, xorig, yorig, (u-u0)/fact, (v-v0)/fact, 1, kx, ky 
  150.  
  151. A = POLY_2D(BYTSCL(img, top=top), kx, ky, KEYWORD_SET(interp), $
  152.         su/fact,sv/fact, missing = miss) ;Warp it
  153. TV, a, u0, v0, xsize = su, ysize = sv, order=0
  154. SURFACE, REBIN(img, nx/sscale, ny/sscale),$
  155.     REBIN(xx, nx/sscale), REBIN(yy, ny/sscale), _EXTRA=es, $
  156.     /SAVE, /NOERASE, XST=1, YST=1, BOT=128 ;Show the surface
  157.                         ; Redraw front-right Z axis.
  158. AXIS,ZAXIS=0,/T3D
  159.             ;And finally, draw contour on top
  160. CONTOUR, img, xx, yy,/T3D,/NOERASE,ZVAL=1.0,XST=1,YST=1, $
  161.     C_COLOR = C_COLOR,/NOCLIP, _EXTRA=ec
  162. end
  163.